package com.qfedu.tantu.service.impl;

import com.qfedu.tantu.dao.CityDao;
import com.qfedu.tantu.dto.Attractionsdto;
import com.qfedu.tantu.entity.Attractions;
import com.qfedu.tantu.entity.City;
import com.qfedu.tantu.service.intf.CityService;
import com.qfedu.tantu.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:rongrong
 * @Description:
 * @Date:Create in 2022/7/2 21:32
 **/

@Service
public class CityServiceImpl implements CityService {
    @Resource
    private CityDao cityDao;

    @Override
    public R selectPage(int start, int size) {

        //计算起始页
        start = (start-1)*size;
        System.out.println(start+".............."+size);
        //进行limit查询
        List<City> cities = cityDao.selectPage(start, size);
        if(cities!=null){
            return R.ok(cities);
        }else return R.fail();
    }

    @Override
    public R showAll(int id) {
        List<Attractionsdto> attractions = cityDao.showAll(id);
        int size = attractions.size();
        if(size>0){
            return R.ok(attractions);
        }else return R.fail();
    }

    @Override
    public R selectIdByName(String name) {
        int i = cityDao.selectIdByName(name);
        if(i>0){
            return R.ok(i);
        }else {
            return R.fail();
        }
    }

    @Override
    public R selectByName(String name) {
        City city = cityDao.selectByName(name);
        if(city!=null) {
            return R.ok(city);
        }else return R.fail();
    }

    /**
     * 通过 游记数量 降序 排列 城市
     * @param
     * @return
     */
    @Override
    public R ord() {
        return R.ok(cityDao.ord());
    }


}
